package cn.matezk.lianlian.controller;

import cn.hutool.json.JSONUtil;
import cn.matezk.lianlian.service.INotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("Eqadmin")
@Slf4j
public class ValveController {
    @Autowired
    private INotifyService notifyService;

    int times = 0;

    @PostMapping("seteq")
    public String seteq(@RequestParam String id, @RequestParam String iccid, @RequestParam String version, @RequestParam String token) {
        log.info(String.format("id: %s iccid: %s version: %s token: %s", id, iccid, version, token));
        return JSONUtil.createObj().set("state", "ok").set("token", token).toString();
    }

    @PostMapping("geteqstate")
    public String geteqstate(@RequestParam String id, String token) {
        log.info(String.format("id: %s token: %s", id, token));
        times ++;
        if (times % 2 == 0) {
            return JSONUtil.createObj().set("state", 1).set("keep", 10).set("next", 60).toString();
        } else {
            return JSONUtil.createObj().set("state", 0).set("next", 60).toString();
        }
    }
}
